Skip to content

Fix for #2009 (empty rectangle issue) - #2022

Merged
cameronwhite merged 14 commits into
PintaProject:masterfrom
Lehonti:fix/zero_rectangle_select
Sep 12, 2026
Merged

cameronwhite merged 14 commits into
PintaProject:masterfrom
Lehonti:fix/zero_rectangle_select

Conversation

@Lehonti

@Lehonti Lehonti commented Mar 7, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2009

Notice that OnMouseDown rounds the coordinates and OnMouseUp doesn't, so when testing for equality the coordinates are different, which shouldn't happen

@cameronwhite

Copy link
Copy Markdown
Member

Yeah this definitely contributes to the issue - we should have a common function for doing this rounding (it also happens inside the handle for the OnMouseMove event, which is inconsistent )

In my testing I was still able to occasionally get it to produce a zero-size rectangle, by tapping my laptop's trackpad while zoomed in.
After adding some printouts the (before rounding) mouse up position is slightly different, and there wasn't a mouse move event.

down 476.6666666666667, 246.66666666666666
up 476.6666666666667, 246.33333333333334

The logic in HasDragged for transforming to view coordinates is suspicious, because when you're zoomed in you can move the mouse by one unit in view space, and still end up with a zero size rectangle in canvas space

@Lehonti

Lehonti commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor Author

@cameronwhite I see. Maybe after these new changes it will work better

@cameronwhite

Copy link
Copy Markdown
Member

Thanks! Having the common function is much nicer

I can still reproduce the same issue though so I think it's somewhat separate from the rounding - being zoomed in far makes it much easier to hit.
I can do some more investigation, but from the printouts I added yesterday it seemed that the issue is that the mouse-up event might be at a slightly different location without reporting that first as a mouse move (and this might be different enough to round to a different canvas coordinate). So HasDragged() can return true (especially when zoomed since it does its comparison in screen coordinates, rather than canvas coordinates) but we don't actually expand the initial empty rectangle with the new position from the mouse up event.

Maybe this needs to be handled at a lower level like BaseTool or the canvas event handlers though. Very likely there are other tools which also have similar assumptions that the "mouse up" event happens at the same position as the last "mouse move" event, and sending out an extra "mouse move" event could work?

@Lehonti Lehonti changed the title Fix for #2009 Fix for #2009 (empty rectangle issue) Mar 12, 2026
@Lehonti

Lehonti commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

Hi again @cameronwhite. I added an extra check (see 87e01f7). We were only checking if the mouse was moved but we weren't checking if movement was in both X and Y. And to revisit: checking for > 0 works because the coordinates are rounded before they are assigned to RectangleHandle.Rectangle. Perhaps we'll need to change the type to RectangleI in the future? Anyway, if there is a zero-sized selection it's shown graphically but it's not committed

@cameronwhite

Copy link
Copy Markdown
Member

Thanks, seems good in my testing 👍

@cameronwhite
cameronwhite merged commit b83d880 into PintaProject:master Sep 12, 2026
6 checks passed
@Lehonti
Lehonti deleted the fix/zero_rectangle_select branch September 12, 2026 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Select Tool] Clicking with the select tool when zoomed in selects an area of 0 pixels

2 participants